//
//  MineViewController.m
//  Mahjong
//
//  Created by mc on 16/8/29.
//  Copyright © 2016年 Elliot. All rights reserved.
//

#import "MineViewController.h"
#import "MineOneTableViewCell.h"
#import "MineTwoTableViewCell.h"
#import "MineThreeTableViewCell.h"
#import "MineSetViewController.h"
#import "MineCollectViewController.h"
#import "MineListViewController.h"
#import "AddressViewController.h"
#import "LoginViewController.h"
#import "MineMessViewController.h"


@interface MineViewController ()<UITableViewDelegate,UITableViewDataSource,twoDelegate,loginDelegate>
@property (nonatomic, strong) UITableView *myTableView;
@end

@implementation MineViewController
//-(void)viewWillAppear:(BOOL)animated{
//    [super viewWillAppear:animated];
//    self.tabBarController.tabBar.hidden = NO;
//}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.myTableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
    self.myTableView.backgroundColor = [UIColor colorWithRed:239/255.0 green:239/255.0 blue:239/255.0 alpha:1];
    [self.view addSubview:self.myTableView];
    self.myTableView.delegate = self;
    self.myTableView.dataSource = self;
//    self.myTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.myTableView.tableFooterView = [[UIView alloc] init];
    [self.myTableView registerNib:[UINib nibWithNibName:@"MineOneTableViewCell" bundle:nil] forCellReuseIdentifier:@"oneCell"];
    [self.myTableView registerNib:[UINib nibWithNibName:@"MineTwoTableViewCell" bundle:nil] forCellReuseIdentifier:@"twoCell"];
    [self.myTableView registerNib:[UINib nibWithNibName:@"MineThreeTableViewCell" bundle:nil] forCellReuseIdentifier:@"threeCell"];
    
   
}


-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 4;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (section == 3) {
        return 2;
    }
    return 1;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 0) {
       MineOneTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"oneCell"];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.delegate = self;
        return cell;
    }
    if (indexPath.section == 1) {
        MineTwoTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"twoCell"];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;

        cell.myDelegate = self;
        return cell;
    }
    if (indexPath.section == 2){
        MineThreeTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"threeCell"];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;

        cell.titleLabel.text = @"设置";
        cell.headImage.image = [UIImage imageNamed:@"me_but_set@2x"];
        return cell;

    }
    if (indexPath.section == 3) {
        MineThreeTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"threeCell"];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;

        if (indexPath.row == 0) {
            cell.headImage.image = [UIImage imageNamed:@"me_but_good@2x"];
            cell.titleLabel.text = @"赏个好评";
        }
        else{
            cell.headImage.image = [UIImage imageNamed:@"me_but_feed@2x"];
        cell.titleLabel.text = @"意见反馈";
        }
        return cell;
    }
    MineThreeTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"threeCell"];
    return cell;
    

}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if (indexPath.section == 2) {

        MineSetViewController *set = [[MineSetViewController alloc] init];
        set.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:set animated:YES];
    }
}
-(void)login{
    if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"login"] isEqualToString:@"yes"]) {
    MineMessViewController *mess = [[MineMessViewController alloc] init];
    mess.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:mess animated:YES];
        return;
    }
    LoginViewController *lo = [[LoginViewController alloc] init];
    lo.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:lo animated:YES];

}
-(void)list{
    MineListViewController *list = [[MineListViewController alloc] init];
    list.hidesBottomBarWhenPushed = YES;

    [self.navigationController pushViewController:list animated:YES];
}
-(void)adress{
    AddressViewController *collect = [[AddressViewController alloc] init];
    collect.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:collect animated:YES];
}
-(void)collect{
    MineCollectViewController *collect = [[MineCollectViewController alloc] init];
    collect.hidesBottomBarWhenPushed = YES;

    [self.navigationController pushViewController:collect animated:YES];
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 0) {
        return (100*SCREENH_HEIGHT)/667;
    }
    if (indexPath.section == 1) {
        return (120*SCREENH_HEIGHT)/667;
    }
    return (44*SCREENH_HEIGHT)/667;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return (15*SCREENH_HEIGHT)/667;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
